﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace DAL
{
    public class News
    {
        public static int insert(NewsEntity _news)
        {
            return Convert.ToInt32(DbHelper.ExecuteScalar("p_News_insert", _news.Type, _news.Title, _news.Subtitle, _news.TitleCss, _news.Source, _news.Context, _news.IsTop, _news.IsShow, _news.AdminId));
        }
        public static void update(NewsEntity _news)
        {
            DbHelper.ExecuteNonQuery("p_News_update", _news.Newsid, _news.Type, _news.Title, _news.Subtitle, _news.TitleCss, _news.Source, _news.Context, _news.IsTop, _news.IsShow);
        }
        public static void delete(int newsid)
        {
            DbHelper.ExecuteNonQuery("p_News_delete",newsid);
        }
        public static NewsEntity getById(int newsId)
        {
            DataRow dr = DbHelper.ExecuteDataRow("p_News_getById", newsId);
            NewsEntity _news = new NewsEntity();
            if (dr != null)
            {
                _news.Newsid = newsId;
                _news.Type = dr["type"].ToString();
                _news.Title = dr["title"].ToString();
                _news.Subtitle = dr["subtitle"].ToString();
                _news.TitleCss = dr["titleCss"].ToString();
                _news.Source = dr["source"].ToString();
                _news.Context = dr["context"].ToString();
                _news.Click = Convert.ToInt32(dr["click"]);
                _news.IsTop = Convert.ToBoolean(dr["isTop"]);
                _news.IsShow = Convert.ToBoolean(dr["isShow"]);
                _news.InputDt = Convert.ToDateTime(dr["inputDt"]);
                _news.AdminId = Convert.ToInt32(dr["adminId"]);
            }
            return _news;
        }
        public static void updateClick(int newsId)
        {
            DbHelper.ExecuteNonQuery("dbo.p_News_updateClick",newsId);
        }
    }
}
